package main

func longestMountain(A []int) int {
	if len(A) < 3 {
		return 0
	}
	left := make([]int, len(A))
	left[0] = 1
	for i := 1; i < len(A); i++ {
		if A[i-1] < A[i] {
			left[i] = left[i-1] + 1
		} else {
			left[i] = 1
		}
	}
	right := make([]int, len(A))
	right[len(A)-1] = 1
	for i := len(A) - 2; i >= 0; i-- {
		if A[i] > A[i+1] {
			right[i] = right[i+1] + 1
		} else {
			right[i] = 1
		}
	}
	max := 0
	for i := range A {
		if left[i] > 1 && right[i] > 1 {
			// i 是山峰
			mountain := left[i] + right[i] - 1
			if mountain > max {
				max = mountain
			}
		}
	}
	return max
}

func main() {
	println(longestMountain([]int{2, 1, 4, 7, 3, 2, 5}))
	println(longestMountain([]int{2, 2, 2}))

}
